package com.ctgu.expresshelper.controller;


import com.ctgu.expresshelper.entity.Express;
import com.ctgu.expresshelper.service.Express.ExpressService;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/express")
public class ExpressController {

    @Autowired
    private ExpressService expressService;

    /**
     * 判断用户是否有该订单
     * @param expressNum
     * @param userid
     * @return
     */
    @GetMapping("/checkExpress")
    public Express selectExpressByNum(String expressNum,String userid){
        return expressService.selectExpressByNum(expressNum,userid);
    }

    /**
     * 添加用户物流信息
     * @param express
     */
    @PostMapping("/addExpress")
    public void addExpress(@RequestBody Express express){
        expressService.addExpress(express);
    }

    /**
     * 删除用户某一物流信息
     * @param expressNum
     * @param userid
     */
    @DeleteMapping("/deleteExpress")
    public void deleteExpress(String expressNum,int userid){
        expressService.deleteExpress(expressNum,userid);
    }

    /**
     * 得到用户所有的物流信息
     * @param userid
     * @return
     */
    @GetMapping("/{userid}")
    public List<Express> getAllExpress(@PathVariable int userid){
        return expressService.selectAllExpressByUserid(userid);
    }

    @GetMapping("/{userid}/{status}")
    public List<Express> getExpressByStatus(@PathVariable int userid,@PathVariable int status){
        return expressService.selectExpressByUseridAndStatus(userid,status);
    }
}
